from enum import Enum

from typing import Union, List, Any

from pydantic import BaseModel, validator

from app.schemas.common import DateTimeModelMixin
from app.schemas.user import UserInfo


class Type(str, Enum):
    audio = 'audio'
    image = 'image'
    text = 'text'


class ConversationStatus(Enum):
    NORMAL = '1'
    HIDDEN = '0'


class ConnectionStatus(Enum):
    CONNECTION = 1
    DISCONNECT = 0


class ConversationsSM(DateTimeModelMixin):
    participant_id: Union[int, None]
    creator_id: Union[str, None]

    class Config:
        orm_mode: True


class MessageSM(DateTimeModelMixin):
    conversation_id: int
    sender_id: int
    receiver_id: int
    message: str
    type: Type

    class Config:
        orm_mode: True


class Item(BaseModel):
    creator_id: int
    participant_id: int
    id: int
    participant: UserInfo
    unread_messages: int
    last_message: Any

class ConversionList(BaseModel):
    list: Union[List[Item], None]

    class Config:
        orm_mode = True
